#import "sprite_game_enemy_7.h"

#import "sprite_game_heart.h"

@implementation SpriteGameEnemy7

- (id)initSpriteGameEnemy7
{
	if ((self = [super initSpriteGameEnemy]))
	{
		objectName_ = "object sprite game enemy type 7";
		
		/*box2d
		*/
		fixtureBody_ = NULL;
		
		/*handle
		*/
		mosquitoHeartHandle_ = nil;
	}
	return self;
}

- (void)dealloc
{
	/*clear mosquito handle
	*/
	if (mosquitoHeartHandle_ != nil)
	{
		mosquitoHeartHandle_.flagMosquito = false;
		mosquitoHeartHandle_.enemyMosquitoHandle = nil;
	}
}

- (void)draw
{
	CGPoint point;
	
	if (nil != mosquitoHeartHandle_)
	{
		point = ccpSub(mosquitoHeartHandle_.positionInPixels, self.positionInPixels);
		glColor4f(0, 0, 0, 1);
		glLineWidth(3.0);
		uiRenderLine(CGPointZero, point);
	}
}

- (void)createBody
{
	int i;
	int _VertexCount;
	float _Ratio;
	b2Vec2 *_Vertex;
	b2PolygonShape _PolygonShape;
	b2FixtureDef _FixtureDef;
	
	[super createBody];
	
	_Ratio = 1 / CMgrGamePhysics::Ratio();
	_FixtureDef.density = 1.0f;
	_FixtureDef.isSensor = true;
	
	_VertexCount = g_CfgGameEnemyDataTable[7].box2d_collision_point_table_body.size();
	_Vertex = ptCreateCollisionVertex(&g_CfgGameEnemyDataTable[7].box2d_collision_point_table_body);
	for (i = 0; i < _VertexCount; ++i)
	{
		_Vertex[i] = ptScaleVector_same(_Vertex[i], _Ratio);
	}
	_PolygonShape.Set(_Vertex, _VertexCount);
	free(_Vertex);
	_FixtureDef.shape = &_PolygonShape;
	fixtureBody_ = box2dBody_->CreateFixture(&_FixtureDef);
}

- (void)destroyBody
{
	[super destroyBody];
	fixtureBody_ = NULL;
}

- (void)PlayEffectMosquito
{
	CCSequence *_Seq;

	if (nil != effectMosquito_)
	{
		[effectMosquito_ stopAllActions];
		_Seq = [CCSequence actions:[CCShow action], [CCAnimate actionWithAnimation:uiCreateAnimationObject(&g_CfgGameEnemyDataTable[type_].ani_mosquito)], [CCHide action], nil];
		[effectMosquito_ runAction:_Seq];
	}
}

- (void)CallBackActionMosquitoMoveToHeartOver:(id)Sender
{
	if (nil != mosquitoHeartHandle_)
	{
		[self PlayAni:ENEMY_ANI_ATTACK];
		[mosquitoHeartHandle_ ActionDark];
		mosquitoHeartHandle_.flagMosquito = false;
		mosquitoHeartHandle_.enemyMosquitoHandle = nil;
		mosquitoHeartHandle_ = nil;
	}
	else
	{
		[self ActionMove];
	}
}

@end